package com.example.mapper;

import com.example.entity.OrderInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author mingtian
 * @version V1.0
 * @Description 订单相关操作
 * @date 2019/11/19 22:33
 */
public interface OrderMapper {

    /**
     * 插入订单方法
     *
     * @param orderInfo
     * @return
     */
    @Insert("insert orderInfo(id,orderId,orderToken,orderStatus,createTime,createUser) values(#{id},#{orderId},#{orderToken},#{orderStatus},#{createTime},#{createUser})")
    int insert(OrderInfo orderInfo);

    /**
     * 根据 orderToken 修改订单状态
     *
     * @param orderToken
     * @param orderStatus
     * @return
     */
    @Update("update orderInfo set orderStatus=#{orderStatus} where orderToken=#{orderToken} ")
    int update(@Param("orderToken") String orderToken, @Param("orderStatus") Integer orderStatus);


    /**
     * 根据 orderToken 查询订单信息
     *
     * @param orderToken
     * @return
     */
    @Select("select id,orderId,orderToken,orderStatus,createTime,createUser from orderInfo where orderToken=#{orderToken}")
    OrderInfo getOrderByOrderToken(String orderToken);

    /**
     * 根据 orderId 查询订单信息
     *
     * @param orderId
     * @return
     */
    @Select("select id,orderId,orderToken,orderStatus,createTime,createUser from orderInfo where orderId=#{orderId}")
    OrderInfo getOrderByOrderId(String orderId);

    /**
     * 查询所有订单信息
     *
     * @return
     */
    @Select("select * from orderInfo")
    List<OrderInfo> listOrder();
}
